package com.yegs.jltqc.controller;

import com.yegs.jltqc.TO.NamePageQuery;
import com.yegs.jltqc.VO.Formwork;
import com.yegs.jltqc.VO.Report;
import com.yegs.jltqc.config.Msg;
import com.yegs.jltqc.service.FormworkService;
import com.yegs.jltqc.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/report")
public class ReportController {

    @Autowired
    private ReportService reportService;

    @PostMapping("/save")
    public Msg save(@RequestBody Report report){
        try{
            return Msg.success("data",reportService.save(report));
        }catch (Exception e){
            return Msg.error(e.getMessage());
        }
    }

    @GetMapping("/list")
    public Msg list(){
        return Msg.success("list",reportService.list());
    }

    @GetMapping("/get")
    public Msg get(@RequestParam Long id){
        return Msg.success("data",reportService.get(id));
    }

    @GetMapping("/getLast")
    public Msg getLast(@RequestParam(required = false) Long id, @RequestParam String mold){
        return Msg.success("data",reportService.getLast(id, mold));
    }
    @GetMapping("/getNext")
    public Msg getNext(@RequestParam(required = false) Long id, @RequestParam String mold){
        return Msg.success("data",reportService.getNext(id, mold));
    }

    @GetMapping("/del")
    public Msg del(@RequestParam Long id){
        reportService.del(id);
        return Msg.success();
    }
    @PostMapping("/query")
    public Msg query(@RequestBody NamePageQuery query){
        return Msg.success("page",reportService.query(query));
    }




}
